package org.bing.flex.helper {
    import mx.utils.StringUtil;

    public class StringHelper {

        public static function endWiths(s:String, block:String):Boolean {
            var slen:int=block.length;
            var llen:int=s.length;
            if (llen < slen) {
                return false;
            }
            llen=llen - slen;
            for (var i:int=0; i < slen; i++) {
                var ch1:String=block.charAt(i);
                var ch2:String=s.charAt(llen + i);
                if (ch1 != ch2) {
                    return false;
                }
            }
            return true;
        }

        public static function isBlank(s:String):Boolean {
            s=StringUtil.trim(s);
            if (s == "") {
                return true;
            } else {
                return StringUtil.isWhitespace(s);
            }
        }

        public static function trim(s:String):String {
            return StringUtil.trim(s);
        }

        public static function toBoolean(s:String):Boolean {
            switch (s) {
                case "1":
                case "true":
                case "yes":
                    return true;
                case "0":
                case "false":
                case "no":
                    return false;
                default:
                    return Boolean(s);
            }
        }
    }
}